{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a name=\"top\"></a><img src=\"source/SpinalHDL.png\" alt=\"SpinalHDL based on Scala\" style=\"width:320px;\" />"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "  Before running Spinal HDL code, be sure to load SpinalHDL Libraries  \n",
    "**Note** : This may be a little slow when the first time load, please wait a moment to download Lib from remote.)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\u001b[36mpath\u001b[39m: \u001b[32mString\u001b[39m = \u001b[32m\"E:\\\\nutstore\\\\2019bf\\\\github\\\\Spinal-bootcamp/source/load-spinal.sc\"\u001b[39m"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "val path = System.getProperty(\"user.dir\") + \"/source/load-spinal.sc\"\n",
    "interp.load.module(ammonite.ops.Path(java.nio.file.FileSystems.getDefault().getPath(path)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Rules\n",
    "\n",
    "- **Spinal never force IO Bundle**\n",
    " ```scala\n",
    " class Top extends Component{\n",
    "   val a = in UInts(8 bits)\n",
    "   val IO = new Bundle{        //IO bundle is not necessary\n",
    "     val b = in UInts(8 bits) \n",
    "   }\n",
    " }\n",
    " ```\n",
    "- **Spinal never force instantiation by Module keywords**\n",
    " ```scala \n",
    "  class Top extends Component{\n",
    "     val cpu = new MyCpu(mycpuconfig) //no need Module(new Mycpu(...))\n",
    "  }\n",
    " ```\n",
    "- **Spinal nerver remove unused named signals**\n",
    "\n",
    "  SpinalHDL left theme to EDA tools, somethimes a named unused signals is convinent for wave debug.  \n",
    "  It will not cause additional problems, EDA tools will optimize it.\n",
    " ```scala \n",
    "  class Top extends Component{\n",
    "     val unused1 = Bits(8 bits)\n",
    "     val unused2 = unsued1\n",
    "  }\n",
    "  ```\n",
    "  but output signal without driving will not allow ,this will cause exception\n",
    "  ```scala \n",
    "  class Top extends Component{\n",
    "     val unassigned = out Bits(8 bits) //not allow, cuase exception\n",
    "  }\n",
    "  ```"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "SpinalHDL will never make any form restrictions， **SpinalHDL emphasize same in essence, not in form**  \n",
    "io signal allow appear anywhere under the scope of component.\n",
    "\n",
    "**So, Why Not:**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "class WhyNot extends Component{\n",
    "   val ram = Mem(Bits(4 bit),16)\n",
    "   out(ram.readWriteSync(in UInt(4 bit),in Bits(4 bit),in Bool,in Bool))\n",
    "   out(ram.readWriteSync(in UInt(4 bit),in Bits(4 bit),in Bool,in Bool))\n",
    "}\n",
    "showRtl(new WhyNot)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## SpinlHDL Data Type\n",
    "The language provides 5 base types and 2 composite types that can be used.\n",
    "\n",
    "Base types: Bool , Bits , UInt for unsigned integers, SInt for signed integers and Enum.\n",
    "\n",
    "Composite types: Bundle and Vec.\n",
    "\n",
    "![image.png](attachment:image.png)\n",
    "\n",
    "Finally, a special type is available for checking equality between a BitVector and a bits constant that contains holes (don’t care values). An example is shown below:\n",
    "```scala\n",
    "val myBits  = Bits(8 bits)\n",
    "val itMatch = myBits === M\"00--10--\" // - don't care value\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Top extends Component{\n",
    "  val myBits  = Bits(8 bits)\n",
    "  val itMatch = myBits === M\"00--10--\" // - don't care value\n",
    "}\n",
    "showRtl(new Top)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Bool\n",
    "Description\n",
    "The Bool type corresponds to a boolean value (True or False).\n",
    "\n",
    "Declaration：   \n",
    "The syntax to declare a boolean value is as follows: (everything between [] is optional)\n",
    "\n",
    "Syntax | Description |Return\n",
    "-|-|-\n",
    "Bool[()] |  Create a Bool  |Bool\n",
    "True | Create a Bool assigned with true | Bool\n",
    "False | Create a Bool assigned with false |Bool\n",
    "Bool(value: Boolean) | Create a Bool assigned with a Scala Boolean(true, false) | Bool\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Top extends Component{\n",
    "  val myBool_1 = Bool          // Create a Bool\n",
    "  myBool_1    := False         // := is the assignment operator\n",
    "\n",
    "  val myBool_2 = False         // Equivalent to the code above\n",
    "\n",
    "  val myBool_3 = Bool(5 < 12)  // Use a Scala Boolean to create a Bool\n",
    "  val myBool_4 = Bool(\"Spinal\" == \"Scala\")  // Use a Scala Boolean to create a Bool\n",
    "}\n",
    "showRtl(new Top)"
   ]
  },
  {
   "attachments": {
    "image.png": {
     "image/png": "iVBORw0KGgoAAAANSUhEUgAAAyYAAACqCAYAAABYrVsMAAAgAElEQVR4Ae3dC3RU1bkH8P8kIZDwMCAGkAABBMQXUB+FWgtt8dqrLWCtld7aJl1arYUWYr0+sC1Qq1brA9T4qhSuxSu1iqC4At6gUKWgEA1iASuPADEhCSRAAgmBkLv2TGfYmeeZyXdm9pn8z1pZ2XNm7+9853c2M9mcs89xtba2toILBShAAQpQgAIUoAAFKECBBAqkJHDb3DQFKEABClCAAhSgAAUoQAG3AAcmMXSE5ubmGFolrgnztdeevvTVBdgfdA35Mn3lTfWI9NU15Mv0lTfVI9JX15Avx8PXxUu5oj9w3/rWt3DZZZchNTU1+sZhWmzYsAFFRUVhasT2FvP1uNHX48D+wP6gf5KwP7A/sD/oAuwPugY/H9gf9P7w+OOPY9q0aUhPT9dXi5Z5xiQGzlWrViElJQVqeo7kz8qVK2PIJnIT5us5TvT19BX2B/YH/VOD/YH9gf0h8Luc3xf8vtD/vmN/8PQHuwclais8Y6J/Ilssu1wu94DEYnXL1RjXQ0UHOuj/aNgf2B/YH3QB9gddg58P7A/sD7qAvf0hcEvya3jGRN6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8fBaf/e4vEck6SYY6J/qLJMAQpQgAIUoAAFKEABCjhPICnmmDiPnRlTgAIUoAAFKEABClCAAroABya6hsVyUVGRxZpmVGO+9h4H+tJXF2B/0DXky/SVN9Uj0lfXkC/TV95Uj0hfXUO+HA9fDkxiOG7Z2aefOh9D87g3Yb72ktOXvroA+4OuIV+mr7ypHpG+uoZ8mb7ypnpE+uoa8uV4+HKOifxxY0QKUIACFKAABShAAQpQIEoBnjGJEozVKUABClCAAhSgAAUoQAF5AQ5M5E0ZkQIUoAAFKEABClCAAhSIUoADkyjBWJ0CFKAABShAAQpQgAIUkBfgwETelBEpQAEKUIACFKAABShAgSgFODCJEozVKUABClCAAhSgAAUoQAF5AQ5M5E0ZkQIUoAAFKEABClCAAhSIUuD/AVOZp3HuNMSzAAAAAElFTkSuQmCC"
    }
   },
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "creat Rise-edge or Fall-edge from level-signal\n",
    "![image.png](attachment:image.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Top extends Component{\n",
    "  val x = Bool          \n",
    "  val pulse1 = x.fall()  \n",
    "  val pulse2 = x.rise()\n",
    "  val pulse3 = x.edge()\n",
    "}\n",
    "showRtl(new Top)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "More method of Bool (see [Bool](https://spinalhdl.github.io/SpinalDoc-RTD/SpinalHDL/Data%20types/bool.html))\n",
    "\n",
    "  \n",
    "   Operator              | Description                                                   |Return type\n",
    "  -|-|-\n",
    "  x.edge\\[()\\]          | Return True when x changes state                              |Bool\n",
    "  x.edge(initAt: Bool)  | Same as x.edge but with a reset value                         |Bool\n",
    "  x.rise\\[()\\]          | Return True when x was low at the last cycle and is now high  |Bool\n",
    "  x.rise(initAt: Bool)  | Same as x.rise but with a reset value                         |Bool\n",
    "  x.fall\\[()\\]          | Return True when x was high at the last cycle and is now low  |Bool\n",
    "  x.fall(initAt: Bool)  | Same as x.fall but with a reset value                         |Bool\n",
    "  x.edges\\[()\\]         | Return a bundle (rise, fall, toggle)                          |BoolEdges\n",
    "  x.edges(initAt: Bool) | Same as x.edges but with a reset value                        |BoolEdges\n",
    "  x.asBits              | Binary cast to Bits                                           |Bits(w(x) bits)\n",
    "  x.asUInt              | Binary cast to UInt                                           |UInt(w(x) bits)\n",
    "  x.asSInt              | Binary cast to SInt                                           |SInt(w(x) bits)\n",
    "  x.asUInt(bitCount)    | Binary cast to UInt and resize                                |UInt(bitCount bits)\n",
    "  x.asBits(bitCount)    | Binary cast to Bits and resize                                |Bits(bitCount bits)         \n",
    "  x ## y | Concatenate, x->high, y->low | Bits(w(x) + w(y) bits)\n",
    "  !x                 |Logical NOT                |Bool\n",
    "  x && y <br> x&y   |Logical AND                |Bool\n",
    "  x \\|\\|y <br> x\\|y     |Logical OR                 |Bool\n",
    "  x \\^ y             |Logical XOR                |Bool\n",
    "  x.set\\[()\\]        |Set x to True              |\n",
    "  x.clear\\[()\\]      |Set x to False             |\n",
    "  x.setWhen(cond)    |Set x when cond is True    |Bool\n",
    "  x.clearWhen(cond)  |Clear x when cond is True  |Bool\n",
    "  x === y  | Equality    | Bool\n",
    "  x =/= y  | Inequality  | Bool       "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Top extends Component{\n",
    "  val x = Bool          \n",
    "  val y = UInt(8 bits)\n",
    "  when(x.edge){\n",
    "      y.setAll\n",
    "  }.otherwise{\n",
    "      y.clearAll\n",
    "  }\n",
    "}\n",
    "showRtl(new Top)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Bits\n",
    "The Bits type corresponds to a vector of bits that does not convey any arithmetic meaning.\n",
    "The syntax to declare a bit vector is as follows: (everything between [] is optional)\n",
    "\n",
    "  Syntax                                  | Description                                                                   | Return\n",
    "  -|-|-                                                                                                                    \n",
    "  Bits \\[()\\]                             | Create a BitVector, bits count is inferred                                    | Bits\n",
    "  Bits(x bits)                            | Create a BitVector with x bits                                                | Bits\n",
    "  B(value: Int\\[, x bits\\])               | Create a BitVector with x bits assigned with \\'value\\'                        | Bits\n",
    "  B\\\"\\[\\[size\\'\\]base\\]value\\\"            | Create a BitVector assigned with \\'value\\' (Base: \\'h\\', \\'d\\', \\'o\\', \\'b\\') | Bits\n",
    "  B(\\[x bits,\\] `element <element>`, ...) | Create a BitVector assigned with the value specified by elements              | Bits "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Top extends Component{ \n",
    "  val x = Bits(8 bits)\n",
    "  val y = x(6 downto 2)\n",
    "}\n",
    "showRtl(new Top)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Top extends Component{ \n",
    "// Declaration\n",
    "val myBits  = Bits()     // the size is inferred\n",
    "val myBits1 = Bits(32 bits)\n",
    "val myBits2 = B(25, 8 bits)\n",
    "val myBits3 = B\"8'xFF\"   // Base could be x,h (base 16)\n",
    "                         //               d   (base 10)\n",
    "                         //               o   (base 8)\n",
    "                         //               b   (base 2)\n",
    "val myBits4 = B\"1001_0011\"  // _ can be used for readability\n",
    "\n",
    "// Element\n",
    "val myBits5 = B(8 bits, default -> True) // \"11111111\"\n",
    "val myBits6 = B(8 bits, (7 downto 5) -> B\"101\", 4 -> true, 3 -> True, default -> false ) // \"10111000\"\n",
    "val myBits7 = Bits(8 bits)\n",
    "myBits7 := (7 -> true, default -> false) // \"10000000\" (For assignement purposes, you can omit the B)\n",
    "myBits  := B(31,8 bits)\n",
    "}\n",
    "showRtl(new Top)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "More method of Bits (see [Bits](https://spinalhdl.github.io/SpinalDoc-RTD/SpinalHDL/Data%20types/bits.html#)) \n",
    "\n",
    "  Operator                    | Description                              | Return type\n",
    "  -|-|-                                                                                                                    \n",
    "  \\~x                         |Bitwise NOT                              |Bits(w(x) bits)\n",
    "  x & y                       |Bitwise AND                              |Bits(w(xy) bits)\n",
    "  x                           |y                                        |Bitwise OR\n",
    "  x \\^ y                      |Bitwise XOR                              |Bits(w(xy) bits)\n",
    "  x.xorR                      |XOR all bits of x                        |Bool\n",
    "  x.orR                       |OR all bits of x                         |Bool\n",
    "  x.andR                      |AND all bits of x                        |Bool\n",
    "  x \\>\\> y                    |Logical shift right, y: Int              |Bits(w(x) - y bits)\n",
    "  x \\>\\> y                    |Logical shift right, y: UInt             |Bits(w(x) bits)\n",
    "  x \\<\\< y                    |Logical shift left, y: Int               |Bits(w(x) + y bits)\n",
    "  x \\<\\< y                    |Logical shift left, y: UInt              |Bits(w(x) + max(y) bits)\n",
    "  x                           |\\>\\> y                                   |Logical shift right, y: Int/UInt\n",
    "  x                           |\\<\\< y                                   |Logical shift left, y: Int/UInt\n",
    "  x.rotateLeft(y)             |Logical left rotation, y: UInt/Int       |Bits(w(x) bits)\n",
    "  x.rotateRight(y)            |Logical right rotation, y: UInt/Int      |Bits(w(x) bits)\n",
    "  x.clearAll\\[()\\]            |Clear all bits                           |   \n",
    "  x.setAll\\[()\\]              |Set all bits                             |    \n",
    "  x.setAllTo(value: Boolean)  |Set all bits to the given Boolean value  |   \n",
    "  x.setAllTo(value: Bool)     |Set all bits to the given Bool value     |   \n",
    "  x === y   |Equality                    | Bool\n",
    "  x =/= y   |Inequality                  | Bool\n",
    "  x.asBits  | Binary cast to Bits        |Bits(w(x) bits)\n",
    "  x.asUInt  | Binary cast to UInt        |UInt(w(x) bits)\n",
    "  x.asSInt  | Binary cast to SInt        |SInt(w(x) bits)\n",
    "  x.asBools | Cast to an array of Bools  |Vec(Bool, w(x))\n",
    "  B(x: T)   | Cast Data to Bits          | Bits(w(x) bits)\n",
    "  x(y)                       | Readbit, y: Int/UInt                                       | Bool\n",
    "  x(hi,lo)                   | Read bitfield, hi: Int, lo: Int                            | Bits(hi-lo+1 bits)\n",
    "  x(offset,width bits)       | Read bitfield, offset: UInt, width: Int                    | Bits(width bits)\n",
    "  x(`range <range>`)         | Read a range of bit. Ex : myBits(4 downto 2)               | Bits(range bits)\n",
    "  x(y) := z                  | Assign bits, y: Int/UInt                                   | Bool\n",
    "  x(offset, width bits) := z | Assign bitfield, offset: UInt, width: Int                  | Bits(width bits)\n",
    "  x(`range <range>`) := z    | Assign a range of bit. Ex : myBits(4 downto 2) := B\"010\" | Bits(range bits)\n",
    "  x.getWidth               |Return bitcount                                                                | Int\n",
    "  x.range                  |Return the range (x.high downto 0)                                             | Range\n",
    "  x.high                   |Return the upper bound of the type x                                           | Int\n",
    "  x.msb                    |Return the most significant bit                                                | Bool\n",
    "  x.lsb                    |Return the least significant bit                                               | Bool\n",
    "  x \\#\\# y                 |Concatenate, x-\\>high, y-\\>low                                                 | Bits(w(x) + w(y) bits)\n",
    "  x.subdivideIn(y slices)  |Subdivide x in y slices, y: Int                                                | Vec(Bits, y)\n",
    "  x.subdivideIn(y bits)    |Subdivide x in multiple slices of y bits, y: Int                               | Vec(Bits, w(x)/y)\n",
    "  x.resize(y)              |Return a resized copy of x, if enlarged, it is filled with zero, y: Int        | Bits(y bits)\n",
    "  x.resized                |Return a version of x which is allowed to be automatically resized were needed | Bits(w(x) bits)\n",
    "  x.resizeLeft(x)          |Resize by keeping MSB at the same place, x:Int                                 | Bits(x bits)      "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Top extends Component{\n",
    "  val cond       = in Bool\n",
    "  val bits_8bits = in Bits(8 bits)\n",
    "  // Bitwise operator\n",
    "  val a, b, c = Bits(32 bits)\n",
    "  c := ~(a & b) //  Inverse(a AND b)\n",
    "  \n",
    "  val all_1 = a.andR // Check that all bits are equal to 1\n",
    "  \n",
    "  // Logical shift\n",
    "  val bits_10bits = bits_8bits << 2  // shift left (results in 10 bits)\n",
    "  val shift_8bits = bits_8bits |<< 2 // shift left (results in 8 bits)\n",
    "  \n",
    "  // Logical rotation\n",
    "  val myBits = bits_8bits.rotateLeft(3) // left bit rotation\n",
    "  \n",
    "  // Set/clear\n",
    "  val d = B\"8'x42\"\n",
    "  when(cond){\n",
    "    d.setAll() // set all bits to True when cond is True\n",
    "  } \n",
    "}\n",
    "showRtl(new Top)    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Top extends Component{\n",
    "  val myBits = in Bits(8 bits)\n",
    "  // cast a Bits to SInt\n",
    "  val mySInt = myBits.asSInt\n",
    "\n",
    "  // create a Vector of bool\n",
    "  val myVec = myBits.asBools\n",
    "\n",
    "  // Cast a SInt to Bits\n",
    "  val myBits2 = B(mySInt)\n",
    "}\n",
    "showRtl(new Top)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## UInt/SInt\n",
    "The UInt/SInt type corresponds to a vector of bits that can be used for signed/unsigned integer arithmetic.\n",
    "The syntax to declare an integer is as follows: (everything between [] is optional)\n",
    "\n",
    " \n",
    "more UInt/SInt will description at **[2.4-Spinal-core-FixPoint.ipynb](2.4-Spinal-core-FixPoint.ipynb)**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Top extends Component{\n",
    "  val myUInt,myUInt1,myUInt2,myUInt3,myUInt4,myUInt5,myUInt6,myUInt7,myUInt8,myUInt9 = UInt(8 bits)\n",
    "  myUInt  := U(2,8 bits)\n",
    "  myUInt1 := U(2)\n",
    "  myUInt2 := U\"0000_0101\"  // Base per default is binary => 5\n",
    "  myUInt3 := U\"h1A\"        // Base could be x (base 16)\n",
    "                          //               h (base 16)\n",
    "                          //               d (base 10)\n",
    "                          //               o (base 8)\n",
    "                          //               b (base 2)\n",
    "  myUInt4 := U\"8'h1A\"\n",
    "  myUInt5 := 2             // You can use scala Int as literal value\n",
    "\n",
    "  val myBool0 = myUInt === U(7 -> true,(6 downto 0) -> false)\n",
    "  val myBool1 = myUInt === U(myUInt.range -> true)\n",
    "\n",
    "  // For assignement purposes, you can omit the U/S, which also alow the use of the [default -> ???] feature\n",
    "  myUInt6 := (default -> true)                        //Assign myUInt with \"11111111\"\n",
    "  myUInt7 := (myUInt.range -> true)                   //Assign myUInt with \"11111111\"\n",
    "  myUInt8 := (7 -> true, default -> false)            //Assign myUInt with \"10000000\"\n",
    "  myUInt9 := ((4 downto 1) -> true, default -> false) //Assign myUInt with \"00011110\"\n",
    "}\n",
    "showRtl(new Top)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Top extends Component{\n",
    "  val mySInt_1,mySInt_2 = in SInt(8 bits)\n",
    "  val myUInt_8bits = in UInt(8 bits)\n",
    "  val myBool0,myBool1 = out Bool()\n",
    "  // Comparaison between two SInt\n",
    "  myBool0 := mySInt_1 > mySInt_2\n",
    "\n",
    "  // Comparaison between a UInt and a literal\n",
    "  myBool1 := myUInt_8bits >= U(3, 8 bits)\n",
    "\n",
    "  when(myUInt_8bits === 3){\n",
    "  \n",
    "  } \n",
    "}\n",
    "showRtl(new Top)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## SpinalEnum\n",
    "The Enumeration type corresponds to a list of named values."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Bundle \n",
    "The Bundle is a composite type that defines a group of named signals (of any SpinalHDL basic type) under a single name.\n",
    "\n",
    "A Bundle can be used to model data structures, buses and interfaces.\n",
    "\n",
    "For more information, see **[3.1-Spinal-lib-flow-stream.ipynb](3.1-Spinal-lib-flow-stream.ipynb)**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "case class myBundle extends Bundle {\n",
    "  val bundleItem0 = AnyType\n",
    "  val bundleItem1 = AnyType\n",
    "  val bundleItemN = AnyType\n",
    "}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Vec\n",
    "A Vec is a composite type that defines a group of indexed signals (of any SpinalHDL basic type) under a single name."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Top extends Component {\n",
    "  // Create a vector of 2 signed integers\n",
    "  val myVecOfSInt = Vec(SInt(8 bits),2)\n",
    "  myVecOfSInt(0) := 2\n",
    "  myVecOfSInt(1) := myVecOfSInt(0) + 3\n",
    "\n",
    "  // Create a vector of 3 different type elements\n",
    "  val myVecOfMixedUInt = Vec(UInt(3 bits), UInt(5 bits), UInt(8 bits))\n",
    "\n",
    "  val x,y,z = UInt(8 bits)\n",
    "  val myVecOf_xyz_ref = Vec(x,y,z)\n",
    "\n",
    "  // Iterate on a vector\n",
    "  for(element <- myVecOf_xyz_ref){\n",
    "    element := 0   //Assign x,y,z with the value 0\n",
    "  }\n",
    "\n",
    "  // Map on vector\n",
    "  myVecOfMixedUInt.map(_ := 0) // assign all element with value 0\n",
    "\n",
    "  // Assign 3 to the first element of the vector\n",
    "  myVecOf_xyz_ref(1).allowOverride := 3\n",
    "}\n",
    "showRtl(new Top)"
   ]
  },
  {
   "attachments": {
    "image.png": {
     "image/png": "iVBORw0KGgoAAAANSUhEUgAAAhYAAAB0CAYAAADZ5HurAAAgAElEQVR4Ae2dCZQURZ7/fyC2yg2KCB70yNGiMCigqwxyjKiL+scBfS68B+MB47F4INuMKOiMII6KM4OM7IwKKAPv6d+3Aw8WZT0YEFhkVxBZW5FWHEDpXgY5muaQBmTfN4pfVlSSVZl1ZHVV1/f3XlVmRkZERnwyIvKXEb+MqHf8+PHjQiEBEiABEiABEiCBDBCon4E4GAUJkAAJkAAJkAAJGAJULFgQSIAESIAESIAEMkaAikXGUDIiEiABEiABEiABKhYsAyRAAkkRqKyslPLy8qTC0DMJkEDhEKBiUTj3mjklgbQIPP3009KpUyfp27evlJSUmP1Ro0alFacdGHHjt27dOts54b6mScO6txrXkCFDYuKGO/zC3ZZFixZRabKBcJ8EUiDQIIUwDEICJFBg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dWF15HyXfK+Lyh+9i/WOey0ZqD64TY/A1jmhGdSkl7DcC11dUySvf9rVSRi+0AlrIhvnItncwTwWW/Lry4Rs4nFfa3F5iVRUR+diuOmmm5IemnTHyWMSMATwVVv5bwkjIIHlW9pJ+a7oCzXslWCfmEjM6qaJPPAcCZAACZAACZAACQQlQMUiKCn6IwESIAESIAES8CVAxcIXET2QAAmQAAmQAAkEJUDFIigp+iMBEiABEiABEvAlQMXCFxE9kAAJkAAJkAAJBCVAxSIoKfojARIgARIgARLwJUDFwhcRPZAACZAACZAACQQlQMUiKCn6IwESIAESIAES8CVAxcIXET2QAAmQAAmQAAkEJUDFIigp+iMBEiABEiABEvAlQMXCFxE9kAAJkAAJkAAJBCVAxSIoKfojARIgARIgARLwJUDFwhcRPZAACZAACZAACQQlQMUiKCn6IwESIAESIAES8CVAxcIXET2QAAmQAAmQAAkEJUDFIigp+iMBEiABEiABEvAlQMXCFxE9kAAJkAAJkAAJBCVAxSIoKfojARIgARIgARLwJUDFwhcRPZAACZAACZAACQQlQMUiKCn6IwESIAESIAES8CVAxcIXET2QAAmQAAmQAAkEJfB/BdG8Vi8ZNlAAAAAASUVORK5CYII="
    }
   },
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## List/Array in Spinal\n",
    "Many times you need to instantiate multiple DUTs, List/Array may be a good choice to implement that.\n",
    "\n",
    "### A casCadeFilter Example\n",
    "\n",
    "![image.png](attachment:image.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "class FIR extends Component{\n",
    "    val fi = slave Flow(SInt(8 bits))\n",
    "    val fo = master Flow(SInt(8 bits)) \n",
    "    \n",
    "    fo << fi.stage()\n",
    "    \n",
    "    def -->(that: FIR):FIR = {\n",
    "        this.fo >> that.fi \n",
    "        that\n",
    "    }\n",
    "}\n",
    "\n",
    "class casCadeFilter extends Component{\n",
    "    val fi = slave Flow(SInt(8 bits))\n",
    "    val fo = master Flow(SInt(8 bits))\n",
    "    \n",
    "    val Firs = List.fill(4)(new FIR)\n",
    "    \n",
    "    Firs(0) --> Firs(1) --> Firs(2) --> Firs(3) \n",
    "  //Firs(0).-->(Firs(1)).-->(Firs(2)).-->(Firs(3))  //scala Infix expression excute from left to right \n",
    "    Firs(0).fi << fi\n",
    "    fo << Firs(3).fo   \n",
    "}\n",
    "showRtl(new casCadeFilter)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For parametric design, you can't link theme one by one `Firs(0) --> Firs(1) --> ....  --> Firs(n)`. \n",
    "\n",
    "The better way is to use the fold or reduce method to automate them `Firs.reduceLeft(_-->_)`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "class casCadeFilter(firNumbers: Int) extends Component{\n",
    "    val fi = slave Flow(SInt(8 bits))\n",
    "    val fo = master Flow(SInt(8 bits))\n",
    "    \n",
    "    val Firs = List.fill(firNumbers)(new FIR)\n",
    "    \n",
    "    Firs.reduceLeft(_-->_)     //you can also connnect like this \n",
    "    \n",
    "    Firs(0).fi << fi\n",
    "    fo << Firs(firNumbers-1).fo   \n",
    "}\n",
    "showRtl(new casCadeFilter(8))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "some interesting  method of List/Array\n",
    "\n",
    "- `foldLeft()()`\n",
    "- `reduceLeft()`\n",
    "- `foldRight()()`\n",
    "- `reduceRight()`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "(1 to 10).foldLeft(0)((a,b)=>{println(s\"$a-->$b\");b})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "(1 to 10).reduceLeft((a,b)=>{println(s\"$a-->$b\");b})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "(1 to 10).foldRight(11)((a,b)=>{println(s\"$a-->$b\");a})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "(1 to 10).reduceRight((a,b)=>{println(s\"$a-->$b\");a})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Scala",
   "language": "scala",
   "name": "scala"
  },
  "language_info": {
   "codemirror_mode": "text/x-scala",
   "file_extension": ".scala",
   "mimetype": "text/x-scala",
   "name": "scala",
   "nbconvert_exporter": "script",
   "version": "2.12.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
